<template>
	<view class="message-category">
		<wd-badge custom-class="badge-wrap" :modelValue="likeAndFavoriteCount" :max="99">
			<view class="category-item" @click="jumpMessageList('like_and_favorite')">
				<image src="/static/m_1.png" class="category-icon"></image>
				<text class="category-name">赞和收藏</text>
			</view>
		</wd-badge>

		<wd-badge custom-class="badge-wrap" :modelValue="tabbarStore.messageStats.follow_count" :max="99">
			<view class="category-item" @click="jumpMessageList('follow')">
				<image src="/static/m_2.png" class="category-icon"></image>
				<text class="category-name">新增关注</text>
			</view>
		</wd-badge>

		<wd-badge custom-class="badge-wrap" :modelValue="tabbarStore.messageStats.comment_count" :max="99">
			<view class="category-item" @click="jumpMessageList('comment')">
				<image src="/static/m_3.png" class="category-icon"></image>
				<text class="category-name">评论</text>
			</view>
		</wd-badge>
	</view>
	<!-- 折叠消息 -->
	<wd-badge :modelValue="tabbarStore.messageStats.system_count" :max="99" :top="40" :right="20">
		<navigator url="/pages/message/system" class="message-cell">
			<image src="/static/m_4.png" class="message-icon" mode="scaleToFill" />
			<view class="message-content">
				<view class="message-title">系统消息</view>
				<view class="message-desc">
					<wd-text :text="tabbarStore.messageStats.new_system?.content || '暂无消息'" :lines="1" size="14px"></wd-text>
				</view>
			</view>
			<view v-if="tabbarStore.messageStats.new_system" class="message-time">{{ formatRelativeTime(tabbarStore.messageStats.new_system?.created_at) }}</view>
		</navigator>
	</wd-badge>
	<q-tabbar :selected="3"></q-tabbar>
</template>

<script setup>
import { computed } from 'vue';
import { useTabbarStore } from '@/store/tabbar';
import { formatRelativeTime } from '@/utils/timeFormat.js';

const tabbarStore = useTabbarStore();
const likeAndFavoriteCount = computed(() => {
	return parseInt(tabbarStore.messageStats.like_count) + parseInt(tabbarStore.messageStats.favorite_count);
});

function jumpMessageList(type) {
	uni.navigateTo({
		url: `/pages/message/list?type=${type}`
	});
}
</script>

<style lang="scss" scoped>
.message-category {
	display: flex;
	padding: 20rpx;

	.category-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: auto;
		font-size: 24rpx;

		.category-icon {
			width: 80rpx;
			height: 80rpx;
		}

		.category-name {
			color: #000;
			margin-top: 10rpx;
		}
	}
}

.message-cell {
	width: calc(100vw - $base-spacing - $base-spacing);
	display: flex;
	align-items: center;
	padding: $base-spacing;

	.message-icon {
		width: 80rpx;
		height: 80rpx;
		border-radius: 8rpx;
		margin-right: 24rpx;
	}

	.message-content {
		flex: 1;
		display: flex;
		flex-direction: column;

		.message-title {
			font-size: 32rpx;
			font-weight: 500;
			color: #333;
		}

		.message-desc {
			font-size: 26rpx;
			color: #999;
		}
	}

	.message-time {
		font-size: 24rpx;
		color: #999;
		margin-left: 20rpx;
		flex-shrink: 0;
	}
}

:deep(.badge-wrap) {
	display: flex;
	margin: 0 auto;
}
</style>
